package com.user.profile.service.label;

import java.util.concurrent.atomic.AtomicInteger;
import org.springframework.stereotype.Component;

/**
 * @Author linlx
 * @Date 2021/9/18 9:16
 * @Description
 **/
@Component
public class ThreadIndexHelper {

  private final ThreadLocal<AtomicInteger> labelIndex = new ThreadLocal<>();

  public synchronized Integer getLabelIndex() {
    if (null == labelIndex.get()) {
      AtomicInteger atomicInteger = new AtomicInteger();
      atomicInteger.set(0);
      labelIndex.set(atomicInteger);
      return atomicInteger.get();
    }
    return labelIndex.get().incrementAndGet();
  }

}
